#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-09-04 8:53 上午
# @Author  : yangdy
# @File    : 2020-09-04.257.二叉树的所有路径
# @Software: PyCharmCE
from tools.my_methods import *


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def binaryTreePaths(self, root: TreeNode) -> List[str]:
        ans = []
        if not root:
            return ans

        def dfs(rt, pos):
            if not rt:
                return
            if rt.left:
                dfs(rt.left, pos + [rt.val])
            if rt.right:
                dfs(rt.right, pos + [rt.val])
            if not rt.left and not rt.right:
                ans.append('->'.join(map(str, pos + [rt.val])))

        dfs(root, [])
        return ans
